package com.lanou3g.code0515.study;

import org.junit.Test;

import java.util.UUID;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/5/15;
 * Otherwise, I don't know who created it either
 */

public class TestUUID {
    @Test
    public void fun(){
        String uuid
                 = UUID.randomUUID().toString();
        System.out.println(uuid);
    }

    public static String getRandomString(){
        String uuid
                = UUID.randomUUID()
                .toString()// 转换成字符串
                .replace("-","")//去掉-
                .toUpperCase();//转成大写字母
        return uuid;
    }

    //aaa.png => uuid.png
    public static String handleFileName(String fileName){
        String name = getRandomString();//获取uuid
        // 找到最后一个.的下标
        int lastIndex = fileName.lastIndexOf(".");
        String expand = fileName
                .substring(lastIndex,fileName.length());
        return name + expand;//拼接成新的文件名
    }

    @Test
    public void test01(){
        String newName = handleFileName("aaa.png");
        System.out.println(newName);
    }




}
